<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<title>绑定店铺列表</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link type="text/css" rel="stylesheet" href="${staticPath}/layui/css/layui.css">
	<link type="text/css" rel="stylesheet" href="${staticPath}/layui/modules/css/common.css">
</head>
<body style="padding:0 30px;">
<blockquote class="layui-elem-quote" style=" border-left: 0px solid #FFFFFF; background-color: #FFFFFF">
	<img src="${staticPath}/layui/modules/images/login/team.png" /> 商户个人中心
</blockquote>
<blockquote class="layui-elem-quote">
	绑定店铺
</blockquote>

	<div>
		<div class="box-submit">
			<label>
				<p>总数：</p>
				<input type="text" class="layui-input" id="total" readonly="readonly" value="${total}" />
			</label>
		</div>
		<div class="box-submit">
			<label>
				<p>日期：</p>
				<input type="text" class="layui-input" id="createDate" readonly="readonly" value="${createDate}" />
			</label>
		</div>
		<c:forEach items="${groups}" var="group">
			<div class="box-submit">
				<label>
					<p><span>*</span>${group.name}：</p>
					<input type="text" class="layui-input group" required  lay-verify="required" name="num" field="${group.name}"/>
				</label>
			</div>
		</c:forEach>
		<div class="button">
			<button class="layui-btn layui-btn-danger" lay-submit="" lay-filter="submit">生成分组</button><br><br>
			<%--<button class="layui-btn layui-btn-danger" lay-submit="" lay-filter="submit-all">下载汇总</button>(请在分组下载完成后操作)--%>
		</div>
	</div>
<script src="${staticPath}/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['jquery','layer','form'], function(){
        var uid = guid();
        var $ = layui.jquery,form = layui.form,layer = layui.layer;

        //监听提交
        form.on('submit(submit)', function(data){
            var group = [];
            $(".group").each(function(index,val){
                if($(val).val()!=""){
                    var g={};
                    g.name = $(val).attr("field");
                    g.size = $(val).val();
                    group.push(g);
				}
            });
            if(group.length==0){
                alert("请先设置分组");
                return false;
            }
            var url= "${adminPath}/client/bale/groupOrder";
            var createDate = $("#createDate").val();
            url = url+'?createDate='+createDate+"&groups="+JSON.stringify(group);

            layer.confirm('确认生成？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                layer.load(1);
                $.ajax({
                    url: encodeURI(encodeURI(url)),
                    type: "POST",
                    dataType: "JSON",
                    success: function(result){
                        layer.closeAll('loading');
                        if(result.ret==0){
                            var url= "${adminPath}/client/clientgroupbale";
                            var createDate = $("#createDate").val();
                            url = url+'?createDate='+createDate;
                            window.open(encodeURI(encodeURI(url)) );
                        }else{
                            layer.alert(result.msg, {icon: 0, title:'警告'});
                        }

                    },
                    error: function () {
                        layer.closeAll('loading');
                        layer.msg("未知错误，请联系管理员！",{icon: 2});
                    }
                });
            }, function(){

            });


        });

        function guid() {
            function S4() {
                return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
            }
            return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
        }
    });

</script>
</body>
</html>